<template>
  <a-row id="globalheader" class="grid-demo" align="center" :wrap="false">
    <a-col flex="auto">
      <a-menu
        mode="horizontal"
        :selected-keys="selectedKeys"
        :default-selected-keys="['1']"
        @menu-item-click="doClickMenu"
      >
        <a-menu-item
          key="0"
          :style="{ padding: 0, marginRight: '12px' }"
          disabled
        >
          <div class="title-bar">
            <a-avatar :style="{ backgroundColor: '#3370ff' }"> Avatar</a-avatar>
            <div class="title">
              {{ store.state.user?.loginUser?.userAccount ?? "未登录" }}
            </div>
          </div>
        </a-menu-item>
        <a-menu-item
          key="/profile/index"
          v-if="store.state.user.loginUser.userRole !== ACCESS_ENUM.NOT_LOGIN"
        >
          首页
        </a-menu-item>
        <a-menu-item
          key="/profile/student"
          v-if="store.state.user.loginUser.userRole === ACCESS_ENUM.ADMIN"
        >
          学生资料
        </a-menu-item>
        <a-menu-item
          key="/profile/jobProvided"
          v-if="store.state.user.loginUser.userRole === ACCESS_ENUM.ADMIN"
        >
          岗位提供
        </a-menu-item>
        <a-menu-item
          key="/profile/studentShow"
          v-if="store.state.user.loginUser.userRole === ACCESS_ENUM.ADMIN"
        >
          老师端学生信息
        </a-menu-item>

        <a-menu-item
          key="/profile/teaJobProvided"
          v-if="store.state.user.loginUser.userRole === ACCESS_ENUM.ADMIN"
        >
          教师提供岗位
        </a-menu-item>
        <a-menu-item
          key="/profile/studentManage"
          v-if="store.state.user.loginUser.userRole === ACCESS_ENUM.ADMIN"
        >
          学生端学生信息
        </a-menu-item>
      </a-menu>
    </a-col>
  </a-row>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
import { computed, ref } from "vue";
import { useStore } from "vuex";
import ACCESS_ENUM from "../access/accessEnum";
import { IconUser } from "@arco-design/web-vue/es/icon";

const router = useRouter();
const store = useStore();

//默认页面
const selectedKeys = ref(["/"]);

// const visibleRoutes = computed(() => {
//   return routes.filter((item, index) => {
//     if (item.meta?.invisible) {
//       return false;
//     }
//     if (!item.children) {
//       return false;
//     }
//     // 判断登录用户是否具有权限看到此菜单
//     if (
//       !checkAccess(store.state.user.loginUser, item?.meta?.access as string)
//     ) {
//       return false;
//     }
//     return true;
//   });
// });

//路由跳转后更新高亮的菜单项
router.afterEach((to, from, failure) => {
  selectedKeys.value = [to.path];
});

const doClickMenu = (key: string) => {
  router.push({
    path: key,
  });
};
</script>
<style scoped>
.title-bar {
  display: flex;
  align-items: center;
}

.title {
  color: #444;
  margin-left: 16px;
}
</style>
